package state;

import state.state.OrderState;
import state.state.impl.PendingPaymentState;

/**
 * 上下文：订单类，持有当前状态
 *
 * @author Liu Yicong
 * @date 2025/9/25
 */
public class OrderContext {
	private OrderState currentState;

	public OrderContext() {
		// 初始状态
		this.currentState = new PendingPaymentState();
		System.out.println("订单创建，初始状态为: " + currentState.getClass().getSimpleName());
	}

	public void setState(OrderState newState) {
		this.currentState = newState;
	}

	public OrderState getCurrentState() {
		return currentState;
	}

	// 客户端调用的方法，委托给当前状态对象
	public void handleProcess() {
		currentState.processOrder(this);
	}

	public void handleCancel() {
		currentState.cancelOrder(this);
	}
}
